home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UTIL / MEMORY / VIRTUASRC / !Virtual / h / swiv < prev    next >
Text File  |  1992-05-19  |  3KB  |  78 lines

  1. /* SWI veneers:
  2.  *  Written by Edward Nevill and Jonathan Roach in an idle moment between projects.
  3.  *  Hacked by BDB to add flag returning 
  4.  */
  5.  
  6. /* Anonymous Error type */
  7. typedef struct Error Error;
  8.  
  9. /* Generic SWI interface
  10.  *  swi(swino,mask,regs...)
  11.  *   swino = SWI number to call as defined in h.swis, X bit set if you wish the
  12.  *           X form of the SWI to be called, clear if you want the non X form.
  13.  *   reg_mask = mask of in / out registers
  14.  *              bits 0-9:   Bit N set => Register N specified on input
  15.  *                          Bit N clear => Register N unspecified on input
  16.  *              bits 22-31: Bit N set => Register N-22 on output stored
  17.  *                              in address specified in varargs list.
  18.  *   ...        In order, input registers followed by output registers,
  19.  *                      starting at r0 and going up.
  20.  *   returns 0 or errorblock pointer if X-bit set
  21.  *   returns r0 if X-bit clear
  22.  *  swix(swino,mask,regs...)
  23.  *   This behaves identically to 'swi' except that it always calls the X form.
  24.  *
  25.  * Eg:
  26.  *   swi(OS_SWINumberToString, IN(R0|R1|R2), n, buf, 255);
  27.  *   e = swi(XOS_SWINumberFromString, IN(R1)|OUT(R0), str, &n);
  28.  *       - Error block pointer (or 0) is returned so must get returned R0
  29.  *       - via argument list.
  30.  *   e = swix(OS_SWINumberFromString, IN(R1)|OUT(R0), str, &n);
  31.  *       - As above but uses the swix function rather that setting the X bit
  32.  *         explicitly (saves one instruction on SWI call).
  33.  *   e = swi(OS_File, IN(R0|R1|R2|R3)|OUT(R4), 255, name, buff, 0, &len);
  34.  *       - We don't care about the load, exec or attrs so don't specify
  35.  *         them in the output registers.
  36.  */
  37.  
  38. extern Error *swix(int swino, int reg_mask, ...);
  39. extern int swi(int swino, int reg_mask, ...);
  40.  
  41. /* Register mask macros
  42.  *  The bits in the register mask are arranged as follows:
  43.  *  31 30 29 ... 22 ...  8 ...  2  1  0
  44.  *  O0 O1 O2 ... O9     I9 ... I2 I1 I0  I(N) = bit set if R(N) used on entry
  45.  *                                       O(N) = bit set if R(N) written on exit
  46.  *  The bits are arranged like this to optimise the case where a SWI is being
  47.  *  called with a small number of input and output registers. For example, a SWI
  48.  *  call which uses R0-R5 on entry and R0-R1 on exit will have a register mask
  49.  *  of 0xC000003f which can be loaded into an ARM register in one instruction
  50.  *  (the compiler performs this optimisation, even when the constant wraps
  51.  *  around between bits 0 and 31). Using the more obvious coding of I0-I9 in bits
  52.  *  0 - 9 and O0-O9 in bits 16-23 leads to a constant of 0x0003003f which require
  53.  *  two instructions.
  54.  */
  55. #define IN(m) (m)
  56. /* old, incorrect version
  57. #define OUT(m) ((unsigned)(m&1)<<31|(m&2)<<29|(m&4)<<27|(m&8)<<25|(m&16)<<23|\
  58.                 (m&32)<<21|(m&64)<<19|(m&128)<<17|(m&256)<<15|(m&512)<<13)
  59. */
  60. #define OUT(m) ((unsigned)((m)&1)<<31|((m)&2)<<29|((m)&4)<<27|\
  61.                 ((m)&8)<<25|((m)&16)<<23|((m)&32)<<21|((m)&64)<<19|\
  62.                 ((m)&128)<<17|((m)&256)<<15|((m)&512)<<13|((m)&1024)<<11)
  63.  
  64. /* The register names
  65.  *  Change these to use different names if you use R0 - R9 elsewhere in your program
  66.  */
  67. #define PSW 0x400       /* Use only in OUT, orders BEFORE others */
  68. #define R0 0x001
  69. #define R1 0x002
  70. #define R2 0x004
  71. #define R3 0x008
  72. #define R4 0x010
  73. #define R5 0x020
  74. #define R6 0x040
  75. #define R7 0x080
  76. #define R8 0x100
  77. #define R9 0x200
  78.